package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
public class CookieSessionController {

    @RequestMapping("cookie")
    public BaseRespVo cookie(HttpServletRequest request) {
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies) {
            System.out.println(cookie.getName() + ":" + cookie.getValue());
        }
        return BaseRespVo.ok();
    }

    @RequestMapping("put/data")
    public BaseRespVo put(HttpSession httpSession) {
        httpSession.setAttribute("songge","niupi ");
        return BaseRespVo.ok();
    }

    @RequestMapping("fetch/data")
    public BaseRespVo fetch(HttpServletRequest request) {
        HttpSession session = request.getSession();
        Object songge = session.getAttribute("songge");
        return BaseRespVo.ok(songge);
    }
}
